<template>
  <el-container class="admin-dashboard">
    <!-- 1. 顶部栏（消息 + 退出） -->
    <el-header class="top-bar">
      <NavHeader />
    </el-header>

    <!-- 2. 主体区 -->
    <el-container>
      <!-- 左侧：角色卡 + 菜单 -->
      <el-aside width="260px">
        <UserProfileCard class="role-card" />
        <el-menu
            :default-active="$route.name"
            class="admin-menu"
            router
            :collapse="false"
            :unique-opened="true"
        >
          <el-menu-item index="AdminStudentAdmin" route="/dashboard/admin/student-admin">
            <el-icon><User /></el-icon>
            <span>学员管理</span>
          </el-menu-item>

          <el-menu-item index="AdminCoachAdmin" route="/dashboard/admin/coach-admin">
            <el-icon><Avatar /></el-icon>
            <span>教练管理</span>
          </el-menu-item>

          <!-- 超级管理员专属 -->
          <el-menu-item
              v-if="isSuperAdmin"
              index="AdminCampusManage"
              route="/dashboard/admin/campus-manage"
          >
            <el-icon><OfficeBuilding /></el-icon>
            <span>校区管理</span>
          </el-menu-item>
          <el-menu-item
              v-if="isSuperAdmin"
              index="AdminAllManage"
              route="/dashboard/admin/admin-manage"
          >
            <el-icon><OfficeBuilding /></el-icon>
            <span>管理员管理</span>
          </el-menu-item>

          <el-menu-item index="AdminCourseAdmin" route="/dashboard/admin/course-admin">
            <el-icon><Calendar /></el-icon>
            <span>课程管理</span>
          </el-menu-item>

          <el-menu-item index="AdminPaymentAdmin" route="/dashboard/admin/payment-admin">
            <el-icon><Money /></el-icon>
            <span>缴费管理</span>
          </el-menu-item>

          <el-menu-item index="AdminMatchManage" route="/dashboard/admin/match-manage">
            <el-icon><Trophy /></el-icon>
            <span>赛事管理</span>
          </el-menu-item>

          <el-menu-item index="AdminSystemLog" route="/dashboard/admin/system-log">
            <el-icon><Document /></el-icon>
            <span>系统日志</span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <!-- 右侧内容 -->
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import NavHeader from '@/views/dashboard/components/NavHeader.vue'
import UserProfileCard from '@/views/dashboard/components/UserProfileCard.vue'
import { useAuthStore } from '@/stores/auth'
import { computed } from 'vue'
import {
  User, Avatar, OfficeBuilding, Calendar, Money, Trophy, Document
} from '@element-plus/icons-vue'

const authStore = useAuthStore()

// 超级管理员判定
const isSuperAdmin = computed(() =>
    authStore.user?.userType === 'admin' && authStore.user?.campus?.id === '1'
)
</script>

<style scoped lang="scss">
.admin-dashboard {
  height: 100vh;
  flex-direction: column;
}
.top-bar {
  height: 60px;
  padding: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}
.role-card {
  margin-bottom: 12px;
}
.admin-menu {
  border-right: none;
}
</style>